﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

namespace MusicOnLine.Common
{    
    public class PageList<T>
    {
        
        public int PageIndex { get; private set; }
        public int PageSize { get; private set; }
        public int TotalCount { get; private set; }
        public int TotalPages { get; private set; }
        public List<T> ItemList
        {
            get;
            private set;
        }
        
        public PageList(IQueryable<T> source, int pageIndex, int pageSize)
        {
            
            this.PageIndex = pageIndex;
            this.PageSize = pageSize;
            this.TotalCount = source.Count();
            this.TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);           
            this.ItemList = source.Skip(pageIndex * pageSize).Take(pageSize).ToList();          
        }

        public bool HasPreviousPage
        {
            get { return (PageIndex > 0); }
        }

        public bool HasNextPage
        {
            get { return ((PageIndex + 1) < TotalPages); }
        }
    }
}
